package com.sky.controller.admin;

import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
@Api(tags = "套餐管理")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    @GetMapping("/page")
    public Result page(SetmealPageQueryDTO setmealPageQueryDTO){
        PageResult p = setmealService.page(setmealPageQueryDTO);
        return Result.success(p);
    }

    @PostMapping("/status/{status}")
    public Result changeStatus(@PathVariable Integer status,Long id){
        setmealService.changeStatus(status,id);
        return Result.success();
    }


    @PostMapping
    public Result add(@RequestBody SetmealVO setmealVO){
        setmealService.add(setmealVO);
        return Result.success();
    }

    @GetMapping("{id}")
    public Result findById(@PathVariable Long id){
        SetmealVO SetmealVO = setmealService.findById(id);
        return Result.success(SetmealVO);
    }

    @DeleteMapping
    public Result deleteByIds(@RequestParam List<Long> ids){
        setmealService.deleteByIds(ids);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody SetmealDTO setmealDTO){
        setmealService.update(setmealDTO);
        return Result.success();
    }
}
